package cn.dakaqi.pingan.util;

import cn.dakaqi.entities.PinganOpen;
import cn.dakaqi.pingan.entities.ActivateResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author chunyang on 2016/1/26.
 */
@SuppressWarnings("unused")
@Component(value = "pingAnUtil")
@Transactional
public class PingAnUtil {
    private static Logger logger = LoggerFactory.getLogger(PingAnUtil.class);
    //内网测试
//    public static final String shopNO = "01001080000007501000";//银企业直连测试商号
//    //public static final String shopNO = "00102079900001231000";//测试:00102079900001231000
//    public static final String B2BiUrl = "http://test.dakaqi.cn:7072";
//    public static final String callBackUrl = "http://test.dakaqi.cn:10000/dakaqi/wap/volunteer/pingan/call-back.action?volunteerCode=";

    //生产服务器
    public static final String shopNO = "00901020000000315000";//生产：00901020000000315000
    public static final String B2BiUrl = "http://test.dakaqi.cn:7072";
    public static final String callBackUrl = "http://test.dakaqi.cn:3030/unicorn/pa/finish?param=";

    //开户、激活
    public static final String tradeNO000001 = "000001";//开户
    public static final String tradeNO000002 = "000002";//激活



    @Autowired
    OpenAccount openAccount;
    @Autowired
    ActivateCard activateCard;
    @Autowired
    PayTools payTools;

    /**
     * 查询账户历史交易明细[4013]
     *
     * @param account   每页个数
     * @param beginDate 开始时间
     * @param endDate   结束时间
     * @param PageNo    页数
     */
    public void queryAllTradeHistory(String account, String beginDate, String endDate, String PageNo) {
        payTools.queryAllTradeHistory(account, beginDate, endDate, PageNo);
    }

    /**
     * 3.10 单笔转账指令查询[4005]
     *
     * @param origThirdVoucher 第三方凭证？
     * @param origFrontLogNo   接待日志编号？
     */
    public void querySingleTradeResult(String origThirdVoucher, String origFrontLogNo) {
        payTools.querySingleTradeResult(origThirdVoucher, origFrontLogNo);
    }

    /**
     * 3.3 企业当日交易明细查询
     */
    public void queryTodayTradeHistory(String account) {
        payTools.queryTodayTradeHistory(account);
    }

    /**
     * 查询余额
     */
    public void queryBalance(String account) {
        payTools.queryBalance(account);
    }

    /**
     * 平安银行银企直连接口 企业单笔资金划转
     */
    public void transferAccounts(String InAcctBankName, String InAcctNo, String InAcctName, String TranAmount) {
        payTools.payMoney(InAcctBankName, InAcctNo, InAcctName, TranAmount);
    }

    /**
     * 开户
     *
     * @param memberCode
     * @param type     类型
     * @param volunteerCode
     * @param userName 用户名称
     * @param IDCard   卡号
     * @param mobile   手机号
     * @param guardianName
     * @param guardianMobile
     * @param guardianIDCard
     * @return 开户信息
     * @throws Exception
     */
    public PinganOpen regAccount(String memberCode,String type, String volunteerCode, String userName, String IDCard, String mobile, String guardianName, String guardianMobile, String guardianIDCard) throws Exception {
        return openAccount.regAccount(memberCode,type, volunteerCode, userName, IDCard, mobile, guardianName, guardianMobile, guardianIDCard);
    }

    /**
     * 激活卡号
     *
     * @param type    类型
     * @param cardNum 卡号
     * @throws Exception
     */
    public ActivateResult activateCard(String type, String volunteerCode, String cardNum) throws Exception {
        return activateCard.activate(type, volunteerCode, cardNum);
    }

    /**
     * 修改指定流水号的激活状态
     *
     * @param volunteerCode 用户编码
     * @param cardNum       卡号
     */
    public void updateActivateRecord(String volunteerCode, String cardNum) {
        try {
            activateCard.updateActivateRecord(volunteerCode, cardNum);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @SuppressWarnings("EmptyTryBlock")
    public static void main(String[] args) throws Exception {
        try {
            //PingAnUtil pingAnUtil1 = PingAnUtil.getInstance();
            //PinganBankRecord pinganBankRecord = pingAnUtil1.regAccount("A","张春洋", "32030519810302243X", "12329117931");
            //PingAnUser{errorMessage='手机号已经被使用', errorCode='0010', state='99', isNew=,  returnUrl='', cardNo=''}
            //PingAnUser{errorMessage='',                 errorCode='',     state='00', isNew=0, returnUrl='', cardNo='6222980110215417'}  已存在
            //PingAnUser{errorMessage='',                 errorCode='',     state='00', isNew=1, returnUrl='', cardNo='6222980110215441'}  新开户

//            <?xml version="1.0" encoding="UTF-8" ?>
//            <Result>
//            <ThirdVoucher>转账凭证号yyyymmddHHSS+8位系列</ThirdVoucher>
//            <FrontLogNo></FrontLogNo>
//            <CcyCode>RMB</CcyCode>
//            <OutAcctName>上海悠活网络科技有限公司</OutAcctName>
//            <OutAcctNo>11015100817002</OutAcctNo>
//            <InAcctBankName>中国银行上海市虹梅路支行</InAcctBankName>
//            <InAcctNo>439059222738</InAcctNo>
//            <InAcctName>上海悠活网络科技有限公司</InAcctName>
//            <TranAmount>10.00</TranAmount>
//            <UnionFlag>0</UnionFlag>
//            <AddrFlag>1</AddrFlag>
//            <Fee1></Fee1>
//            <Fee2></Fee2>
//            </Result>


        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}
